package com.wzcl.app.controller;

import com.wzcl.app.dao.model.Specifications;
import com.wzcl.app.model.common.RVO;
import com.wzcl.app.model.common.ValidList;
import com.wzcl.app.model.dto.SpecificationsDto;
import com.wzcl.app.service.SpecificationsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Log4j2
@RestController
@RequestMapping("/spec")
@Api(value = "商品规格controller", tags = {"商品规格相关接口"})
public class SpecificationsController {

    @Resource
    private SpecificationsService service;

    @ApiOperation("添加规格")
    @PostMapping("/add")
    public RVO<List<Specifications>> addSpecifications(@RequestBody @Valid ValidList<SpecificationsDto> validList){
        List<Specifications> list = service.addAll(validList.getList());
        return RVO.success(list);
    }

    @ApiOperation("规格大小")
    @GetMapping("/get/{commodityId}")
    public RVO<List<Specifications>> getSpecifications(@PathVariable Integer commodityId){
        List<Specifications> list = service.getAllByCommodityId(commodityId);
        return RVO.success(list);
    }
}
